﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.SectionProperties
{
    [XmlRoot("cols", Namespace = Constants.WordMain)]
    public class ColumnDefinitions : XmlSerializable, ISectionPropElement
    {
        [Optional]
        [XmlAttribute("equalWidth", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_OnOff> EqualWidth { get; set; }

        /// <summary>
        /// Spacing Between Equal Width Columns
        /// </summary>
        [Optional]
        [XmlAttribute("space", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Space { get; set; }

        [Optional]
        [XmlAttribute("num", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> NumberOfEqualWidthColumns { get; set; }

        /// <summary>
        /// Draw Line Between Columns
        /// </summary>
        [Optional]
        [XmlAttribute("sep", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_OnOff> Separator { get; set; }

        [XmlElement("col", Namespace = Constants.WordMain)]
        public XmlList<ColumnDefinition> Definitions { get; set; }

        public ColumnDefinitions()
        {
            Definitions = new XmlList<ColumnDefinition>();
        }

        public void Copy(object obj)
        {
            if (obj is ColumnDefinitions)
            {
                this.Space = (obj as ColumnDefinitions).Space;
                this.Separator = (obj as ColumnDefinitions).Separator;
                this.EqualWidth = (obj as ColumnDefinitions).EqualWidth;
                this.Definitions = (obj as ColumnDefinitions).Definitions;
                this.NumberOfEqualWidthColumns = (obj as ColumnDefinitions).NumberOfEqualWidthColumns;
            }
        }
    }

    [XmlRoot("col", Namespace = Constants.WordMain)]
    public class ColumnDefinition : XmlSerializable
    {
        [Optional]
        [XmlAttribute("w", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Width { get; set; }

        [Optional]
        [XmlAttribute("space", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Space { get; set; }

        public ColumnDefinition() { }
    }
}
